const express = function () {
  let tasks = [];

  function nextFunc(res, req) {
    const fn = tasks.shift();
    fn && fn(res, req, nextFunc);
  }

  function use(fn) {
    tasks.push(fn);
    nextFunc();
  }

  return { use, nextFunc };
};

const app = express();

app.use((req, res, next) => {
  console.log("hahah", req, res);
  next();
});
app.use((req, res, next) => {
  console.log("xoxoxo");
  next();
});
